home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-admin / link-manager.php < prev    next >
Encoding:
PHP Script  |  2005-04-09  |  29.8 KB  |  756 lines

  1. <?php
  2. // Links
  3. // Copyright (C) 2002, 2003 Mike Little -- mike@zed1.com
  4.  
  5. require_once('admin.php');
  6.  
  7. $title = __('Manage Links');
  8. $this_file = $parent_file = 'link-manager.php';
  9.  
  10. function xfn_check($class, $value = '', $type = 'check') {
  11.     global $link_rel;
  12.     $rels = preg_split('/\s+/', $link_rel);
  13.  
  14.     if ('' != $value && in_array($value, $rels) ) {
  15.         echo ' checked="checked"';
  16.     }
  17.  
  18.     if ('' == $value) {
  19.         if ('family' == $class && !strstr($link_rel, 'child') && !strstr($link_rel, 'parent') && !strstr($link_rel, 'sibling') && !strstr($link_rel, 'spouse') && !strstr($link_rel, 'kin')) echo ' checked="checked"';
  20.         if ('friendship' == $class && !strstr($link_rel, 'friend') && !strstr($link_rel, 'acquaintance') && !strstr($link_rel, 'contact') ) echo ' checked="checked"';
  21.         if ('geographical' == $class && !strstr($link_rel, 'co-resident') && !strstr($link_rel, 'neighbor') ) echo ' checked="checked"';
  22.         if ('identity' == $class && in_array('me', $rels) ) echo ' checked="checked"';
  23.     }
  24. }
  25.  
  26. function category_dropdown($fieldname, $selected = 0) {
  27.     global $wpdb;
  28.     
  29.     $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
  30.     echo "\n<select name='$fieldname' size='1'>";
  31.     foreach ($results as $row) {
  32.         echo "\n\t<option value='$row->cat_id'";
  33.         if ($row->cat_id == $selected)
  34.             echo " selected='selected'";
  35.         echo ">$row->cat_id: ".wp_specialchars($row->cat_name);
  36.         if ('Y' == $row->auto_toggle)
  37.             echo ' (auto toggle)';
  38.         echo "</option>\n";
  39.     }
  40.     echo "\n</select>\n";
  41. }
  42.  
  43. $wpvarstoreset = array('action','cat_id', 'linkurl', 'name', 'image',
  44.                        'description', 'visible', 'target', 'category', 'link_id',
  45.                        'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel',
  46.                        'notes', 'linkcheck[]');
  47.  
  48. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  49.     $wpvar = $wpvarstoreset[$i];
  50.     if (!isset($$wpvar)) {
  51.         if (empty($_POST["$wpvar"])) {
  52.             if (empty($_GET["$wpvar"])) {
  53.                 $$wpvar = '';
  54.             } else {
  55.                 $$wpvar = $_GET["$wpvar"];
  56.             }
  57.         } else {
  58.             $$wpvar = $_POST["$wpvar"];
  59.         }
  60.     }
  61. }
  62.  
  63. $links_show_cat_id = $_COOKIE['links_show_cat_id_' . COOKIEHASH];
  64. $links_show_order = $_COOKIE['links_show_order_' . COOKIEHASH];
  65.  
  66. if ('' != $_POST['assign']) $action = 'assign';
  67. if ('' != $_POST['visibility']) $action = 'visibility';
  68. if ('' != $_POST['move']) $action = 'move';
  69. if ('' != $_POST['linkcheck']) $linkcheck = $_POST[linkcheck];
  70.  
  71. switch ($action) {
  72.   case 'assign':
  73.   {
  74.     check_admin_referer();
  75.  
  76.     // check the current user's level first.
  77.     if ($user_level < 5)
  78.       die (__("Cheatin' uh ?"));
  79.  
  80.     //for each link id (in $linkcheck[]): if the current user level >= the
  81.     //userlevel of the owner of the link then we can proceed.
  82.  
  83.     if (count($linkcheck) == 0) {
  84.         header('Location: ' . $this_file);
  85.         exit;
  86.     }
  87.     $all_links = join(',', $linkcheck);
  88.     $results = $wpdb->get_results("SELECT link_id, link_owner, user_level FROM $wpdb->links LEFT JOIN $wpdb->users ON link_owner = ID WHERE link_id in ($all_links)");
  89.     foreach ($results as $row) {
  90.       if (($user_level >= $row->user_level)) { // ok to proceed
  91.         $ids_to_change[] = $row->link_id;
  92.       }
  93.     }
  94.  
  95.     // should now have an array of links we can change
  96.     $all_links = join(',', $ids_to_change);
  97.     $q = $wpdb->query("update $wpdb->links SET link_owner='$newowner' WHERE link_id IN ($all_links)");
  98.  
  99.     header('Location: ' . $this_file);
  100.     break;
  101.   }
  102.   case 'visibility':
  103.   {
  104.     check_admin_referer();
  105.  
  106.     // check the current user's level first.
  107.     if ($user_level < 5)
  108.       die (__("Cheatin' uh ?"));
  109.  
  110.     //for each link id (in $linkcheck[]): toggle the visibility
  111.     if (count($linkcheck) == 0) {
  112.         header('Location: ' . $this_file);
  113.         exit;
  114.     }
  115.     $all_links = join(',', $linkcheck);
  116.     $results = $wpdb->get_results("SELECT link_id, link_visible FROM $wpdb->links WHERE link_id in ($all_links)");
  117.     foreach ($results as $row) {
  118.         if ($row->link_visible == 'Y') { // ok to proceed
  119.             $ids_to_turnoff[] = $row->link_id;
  120.         } else {
  121.             $ids_to_turnon[] = $row->link_id;
  122.         }
  123.     }
  124.  
  125.     // should now have two arrays of links to change
  126.     if (count($ids_to_turnoff)) {
  127.         $all_linksoff = join(',', $ids_to_turnoff);
  128.         $q = $wpdb->query("update $wpdb->links SET link_visible='N' WHERE link_id IN ($all_linksoff)");
  129.     }
  130.  
  131.     if (count($ids_to_turnon)) {
  132.         $all_linkson = join(',', $ids_to_turnon);
  133.         $q = $wpdb->query("update $wpdb->links SET link_visible='Y' WHERE link_id IN ($all_linkson)");
  134.     }
  135.  
  136.     header('Location: ' . $this_file);
  137.     break;
  138.   }
  139.   case 'move':
  140.   {
  141.     check_admin_referer();
  142.  
  143.     // check the current user's level first.
  144.     if ($user_level < 5)
  145.       die (__("Cheatin' uh ?"));
  146.  
  147.     //for each link id (in $linkcheck[]) change category to selected value
  148.     if (count($linkcheck) == 0) {
  149.         header('Location: ' . $this_file);
  150.         exit;
  151.     }
  152.     $all_links = join(',', $linkcheck);
  153.     // should now have an array of links we can change
  154.     $q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)");
  155.  
  156.     header('Location: ' . $this_file);
  157.     break;
  158.   }
  159.  
  160.   case 'Add':
  161.   {
  162.     check_admin_referer();
  163.  
  164.     $link_url = wp_specialchars($_POST['linkurl']);
  165.     $link_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $link_url) ? $link_url : 'http://' . $link_url; 
  166.     $link_name = wp_specialchars($_POST['name']);
  167.     $link_image = wp_specialchars($_POST['image']);
  168.     $link_target = $_POST['target'];
  169.     $link_category = $_POST['category'];
  170.     $link_description = $_POST['description'];
  171.     $link_visible = $_POST['visible'];
  172.     $link_rating = $_POST['rating'];
  173.     $link_rel = $_POST['rel'];
  174.     $link_notes = $_POST['notes'];
  175.     $link_rss_uri =  wp_specialchars($_POST['rss_uri']);
  176.     $auto_toggle = get_autotoggle($link_category);
  177.  
  178.     if ($user_level < 5)
  179.       die (__("Cheatin' uh ?"));
  180.  
  181.     // if we are in an auto toggle category and this one is visible then we
  182.     // need to make the others invisible before we add this new one.
  183.     if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
  184.       $wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category");
  185.     }
  186.     $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) " .
  187.       " VALUES('" . $link_url . "','"
  188.            . $link_name . "', '"
  189.            . $link_image . "', '$link_target', $link_category, '"
  190.            . $link_description . "', '$link_visible', $user_ID, $link_rating, '" . $link_rel . "', '" . $link_notes . "', '$link_rss_uri')");
  191.  
  192.     header('Location: ' . $_SERVER['HTTP_REFERER'] . '?added=true');
  193.     break;
  194.   } // end Add
  195.  
  196.   case 'editlink':
  197.   {
  198.     if (isset($submit)) {
  199.  
  200.       if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
  201.         $cat_id = $links_show_cat_id;
  202.  
  203.       if (!isset($cat_id) || ($cat_id == '')) {
  204.         if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
  205.           $cat_id = 'All';
  206.       }
  207.       $links_show_cat_id = $cat_id;
  208.  
  209.       check_admin_referer();
  210.  
  211.       $link_id = (int) $_POST['link_id'];
  212.       $link_url = wp_specialchars($_POST['linkurl']);
  213.       $link_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $link_url) ? $link_url : 'http://' . $link_url; 
  214.       $link_name = wp_specialchars($_POST['name']);
  215.       $link_image = wp_specialchars($_POST['image']);
  216.       $link_target = wp_specialchars($_POST['target']);
  217.       $link_category = $_POST['category'];
  218.       $link_description = $_POST['description'];
  219.       $link_visible = $_POST['visible'];
  220.       $link_rating = $_POST['rating'];
  221.       $link_rel = $_POST['rel'];
  222.       $link_notes = $_POST['notes'];
  223.       $link_rss_uri =  $_POST['rss_uri'];
  224.       $auto_toggle = get_autotoggle($link_category);
  225.  
  226.       if ($user_level < 5)
  227.         die (__("Cheatin' uh ?"));
  228.  
  229.       // if we are in an auto toggle category and this one is visible then we
  230.       // need to make the others invisible before we update this one.
  231.       if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
  232.         $wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category");
  233.       }
  234.  
  235.       $wpdb->query("UPDATE $wpdb->links SET link_url='" . $link_url . "',
  236.       link_name='" . $link_name . "',\n link_image='" . $link_image . "',
  237.       link_target='$link_target',\n link_category=$link_category,
  238.       link_visible='$link_visible',\n link_description='" . $link_description . "',
  239.       link_rating=$link_rating,
  240.       link_rel='" . $link_rel . "',
  241.       link_notes='" . $link_notes . "',
  242.       link_rss = '$link_rss_uri'
  243.       WHERE link_id=$link_id");
  244.     } // end if save
  245.     setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
  246.     wp_redirect($this_file);
  247.     break;
  248.   } // end Save
  249.  
  250.   case 'Delete':
  251.   {
  252.     check_admin_referer();
  253.  
  254.     $link_id = (int) $_GET['link_id'];
  255.  
  256.     if ($user_level < 5)
  257.       die (__("Cheatin' uh ?"));
  258.  
  259.     $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = $link_id");
  260.  
  261.     if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
  262.         $cat_id = $links_show_cat_id;
  263.  
  264.     if (!isset($cat_id) || ($cat_id == '')) {
  265.         if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
  266.         $cat_id = 'All';
  267.     }
  268.     $links_show_cat_id = $cat_id;
  269.     setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
  270.     wp_redirect($this_file);
  271.     break;
  272.   } // end Delete
  273.  
  274.   case 'linkedit': {
  275.     $xfn = true;
  276.     include_once ('admin-header.php');
  277.     if ($user_level < 5)
  278.       die(__('You do not have sufficient permissions to edit the links for this blog.'));
  279.  
  280.     $link_id = (int) $_GET['link_id'];
  281.     $row = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = $link_id");
  282.  
  283.     if ($row) {
  284.       $link_url = wp_specialchars($row->link_url, 1);
  285.       $link_name = wp_specialchars($row->link_name, 1);
  286.       $link_image = $row->link_image;
  287.       $link_target = $row->link_target;
  288.       $link_category = $row->link_category;
  289.       $link_description = wp_specialchars($row->link_description);
  290.       $link_visible = $row->link_visible;
  291.       $link_rating = $row->link_rating;
  292.       $link_rel = $row->link_rel;
  293.       $link_notes = wp_specialchars($row->link_notes);
  294.       $link_rss_uri = wp_specialchars($row->link_rss);
  295.     } else {
  296.         die( __('Link not found.') ); 
  297.     }
  298.  
  299. ?>
  300.  
  301. <div class="wrap"> 
  302.   <form action="" method="post" name="editlink" id="editlink"> 
  303.   <h2><?php _e('Edit a link:') ?></h2>
  304. <fieldset class="options">
  305.     <legend><?php _e('Basics') ?></legend>
  306.         <table class="editform" width="100%" cellspacing="2" cellpadding="5">
  307.          <tr>
  308.            <th width="33%" scope="row"><?php _e('URI:') ?></th>
  309.            <td width="67%"><input type="text" name="linkurl" value="<?php echo $link_url; ?>" style="width: 95%;" /></td>
  310.          </tr>
  311.          <tr>
  312.            <th scope="row"><?php _e('Link Name:') ?></th>
  313.            <td><input type="text" name="name" value="<?php echo $link_name; ?>" style="width: 95%" /></td>
  314.          </tr>
  315.          <tr>
  316.             <th scope="row"><?php _e('Short description:') ?></th>
  317.              <td><input type="text" name="description" value="<?php echo $link_description; ?>" style="width: 95%" /></td>
  318.              </tr>
  319.         <tr>
  320.            <th scope="row"><?php _e('Category:') ?></th>
  321.            <td><?php category_dropdown('category', $link_category); ?></td>
  322.          </tr>
  323. </table>
  324. </fieldset>
  325.        <p class="submit">
  326.        <input type="submit" name="submit" value="<?php _e('Save Changes »') ?>" />
  327.        </p>
  328.     <fieldset class="options">
  329.         <legend><?php _e('Link Relationship (XFN)') ?></legend>
  330.         <table class="editform" width="100%" cellspacing="2" cellpadding="5">
  331.             <tr>
  332.                 <th width="33%" scope="row"><?php _e('rel:') ?></th>
  333.                 <td width="67%"><input type="text" name="rel" id="rel" size="50" value="<?php echo $link_rel; ?>" /></td>
  334.                </tr>
  335.             <tr>
  336.                 <th scope="row"><?php _e('<a href="http://gmpg.org/xfn/">XFN</a> Creator:') ?></th>
  337.                 <td>
  338.                     <table cellpadding="3" cellspacing="5">
  339.               <tr>
  340.               <th scope="row"> <?php _e('identity') ?> </th>
  341.               <td>
  342.                 <label for="me">
  343.                 <input type="checkbox" name="identity" value="me" id="me" <?php xfn_check('identity', 'me'); ?> />
  344.           <?php _e('another web address of mine') ?></label>
  345.               </td>
  346.             </tr>
  347.             <tr>
  348.               <th scope="row"> <?php _e('friendship') ?> </th>
  349.               <td>
  350.                 <label for="contact">
  351.                 <input class="valinp" type="radio" name="friendship" value="contact" id="contact" <?php xfn_check('friendship', 'contact', 'radio'); ?> /> <?php _e('contact') ?></label>
  352.                 <label for="acquaintance">
  353.                 <input class="valinp" type="radio" name="friendship" value="acquaintance" id="acquaintance" <?php xfn_check('friendship', 'acquaintance', 'radio'); ?> />  <?php _e('acquaintance') ?></label>
  354.                 <label id="friend">
  355.                 <input class="valinp" type="radio" name="friendship" value="friend" id="friend" <?php xfn_check('friendship', 'friend', 'radio'); ?> /> <?php _e('friend') ?></label>
  356.                 <label for="friendship">
  357.                 <input name="friendship" type="radio" class="valinp" value="" id="friendship" <?php xfn_check('friendship', '', 'radio'); ?> /> <?php _e('none') ?></label>
  358.               </td>
  359.             </tr>
  360.             <tr>
  361.               <th scope="row"> <?php _e('physical') ?> </th>
  362.               <td>
  363.                 <label for="met">
  364.                 <input class="valinp" type="checkbox" name="physical" value="met" id="met" <?php xfn_check('physical', 'met'); ?> />
  365.           <?php _e('met') ?></label>
  366.               </td>
  367.             </tr>
  368.             <tr>
  369.               <th scope="row"> <?php _e('professional') ?> </th>
  370.               <td>
  371.                 <label for="co-worker">
  372.                 <input class="valinp" type="checkbox" name="professional" value="co-worker" id="co-worker" <?php xfn_check('professional', 'co-worker'); ?> />
  373.           <?php _e('co-worker') ?></label>
  374.                 <label for="colleague">
  375.                 <input class="valinp" type="checkbox" name="professional" value="colleague" id="colleague" <?php xfn_check('professional', 'colleague'); ?> />
  376.           <?php _e('colleague') ?></label>
  377.               </td>
  378.             </tr>
  379.             <tr>
  380.               <th scope="row"> <?php _e('geographical') ?> </th>
  381.               <td>
  382.                 <label for="co-resident">
  383.                 <input class="valinp" type="radio" name="geographical" value="co-resident" id="co-resident" <?php xfn_check('geographical', 'co-resident', 'radio'); ?> />
  384.           <?php _e('co-resident') ?></label>
  385.                 <label for="neighbor">
  386.                 <input class="valinp" type="radio" name="geographical" value="neighbor" id="neighbor" <?php xfn_check('geographical', 'neighbor', 'radio'); ?> />
  387.           <?php _e('neighbor') ?></label>
  388.                 <label for="geographical">
  389.                 <input class="valinp" type="radio" name="geographical" value="" id="geographical" <?php xfn_check('geographical', '', 'radio'); ?> />
  390.           <?php _e('none') ?></label>
  391.               </td>
  392.             </tr>
  393.             <tr>
  394.               <th scope="row"> <?php _e('family') ?> </th>
  395.               <td>
  396.                 <label for="child">
  397.                 <input class="valinp" type="radio" name="family" value="child" id="child" <?php xfn_check('family', 'child', 'radio'); ?>  />
  398.           <?php _e('child') ?></label>
  399.                 <label for="kin">
  400.                 <input class="valinp" type="radio" name="family" value="kin" id="kin" <?php xfn_check('family', 'kin', 'radio'); ?>  />
  401.           <?php _e('kin') ?></label>
  402.                 <label for="parent">
  403.                 <input class="valinp" type="radio" name="family" value="parent" id="parent" <?php xfn_check('family', 'parent', 'radio'); ?> />
  404.           <?php _e('parent') ?></label>
  405.                 <label for="sibling">
  406.                 <input class="valinp" type="radio" name="family" value="sibling" id="sibling" <?php xfn_check('family', 'sibling', 'radio'); ?> />
  407.           <?php _e('sibling') ?></label>
  408.                 <label for="spouse">
  409.                 <input class="valinp" type="radio" name="family" value="spouse" id="spouse" <?php xfn_check('family', 'spouse', 'radio'); ?> />
  410.           <?php _e('spouse') ?></label>
  411.                 <label for="family">
  412.                 <input class="valinp" type="radio" name="family" value="" id="family" <?php xfn_check('family', '', 'radio'); ?> />
  413.           <?php _e('none') ?></label>
  414.               </td>
  415.             </tr>
  416.             <tr>
  417.               <th scope="row"> <?php _e('romantic') ?> </th>
  418.               <td>
  419.                 <label for="muse">
  420.                 <input class="valinp" type="checkbox" name="romantic" value="muse" id="muse" <?php xfn_check('romantic', 'muse'); ?> />
  421.          <?php _e('muse') ?></label>
  422.                 <label for="crush">
  423.                 <input class="valinp" type="checkbox" name="romantic" value="crush" id="crush" <?php xfn_check('romantic', 'crush'); ?> />
  424.          <?php _e('crush') ?></label>
  425.                 <label for="date">
  426.                 <input class="valinp" type="checkbox" name="romantic" value="date" id="date" <?php xfn_check('romantic', 'date'); ?> />
  427.          <?php _e('date') ?></label>
  428.                 <label for="romantic">
  429.                 <input class="valinp" type="checkbox" name="romantic" value="sweetheart" id="romantic" <?php xfn_check('romantic', 'sweetheart'); ?> />
  430.          <?php _e('sweetheart') ?></label>
  431.               </td>
  432.             </tr>
  433.         </table>
  434.           </td>
  435.                </tr>
  436. </table>
  437. </fieldset>
  438.        <p class="submit">
  439.        <input type="submit" name="submit" value="<?php _e('Save Changes »') ?>" />
  440.        </p>
  441. <fieldset class="options">
  442.         <legend><?php _e('Advanced') ?></legend>
  443.         <table class="editform" width="100%" cellspacing="2" cellpadding="5">
  444.          <tr>
  445.            <th width="33%" scope="row"><?php _e('Image URI:') ?></th>
  446.            <td width="67%"><input type="text" name="image" size="50" value="<?php echo $link_image; ?>" style="width: 95%" /></td>
  447.          </tr>
  448. <tr>
  449.            <th scope="row"><?php _e('RSS URI:') ?> </th>
  450.            <td><input name="rss_uri" type="text" id="rss_uri" value="<?php echo $link_rss_uri; ?>" size="50" style="width: 95%" /></td>
  451.          </tr>
  452.          <tr>
  453.            <th scope="row"><?php _e('Notes:') ?></th>
  454.            <td><textarea name="notes" cols="50" rows="10" style="width: 95%"><?php echo $link_notes; ?></textarea></td>
  455.          </tr>
  456.          <tr>
  457.            <th scope="row"><?php _e('Rating:') ?></th>
  458.            <td><select name="rating" size="1">
  459. <?php
  460.     for ($r = 0; $r < 10; $r++) {
  461.       echo('            <option value="'.$r.'" ');
  462.       if ($link_rating == $r)
  463.         echo 'selected="selected"';
  464.       echo('>'.$r.'</option>');
  465.     }
  466. ?>
  467.            </select>
  468.           <?php _e('(Leave at 0 for no rating.)') ?> </td>
  469.          </tr>
  470.          <tr>
  471.            <th scope="row"><?php _e('Target') ?></th>
  472.            <td><label>
  473.           <input type="radio" name="target" value="_blank"   <?php echo(($link_target == '_blank') ? 'checked="checked"' : ''); ?> />
  474.           <code>_blank</code></label><br />
  475. <label>
  476. <input type="radio" name="target" value="_top" <?php echo(($link_target == '_top') ? 'checked="checked"' : ''); ?> />
  477. <code>_top</code></label><br />
  478. <label>
  479. <input type="radio" name="target" value=""     <?php echo(($link_target == '') ? 'checked="checked"' : ''); ?> />
  480. <?php _e('none') ?></label><br />
  481. <?php _e('(Note that the <code>target</code> attribute is illegal in XHTML 1.1 and 1.0 Strict.)') ?></td>
  482.          </tr>
  483.          <tr>
  484.            <th scope="row"><?php _e('Visible:') ?></th>
  485.            <td><label>
  486.              <input type="radio" name="visible" <?php if ($link_visible == 'Y') echo "checked='checked'"; ?> value="Y" />
  487. <?php _e('Yes') ?></label><br /><label>
  488. <input type="radio" name="visible" <?php if ($link_visible == 'N') echo "checked='checked'"; ?> value="N" />
  489. <?php _e('No') ?></label></td>
  490.          </tr>
  491. </table>
  492. </fieldset>
  493. <p class="submit"><input type="submit" name="submit" value="<?php _e('Save Changes »') ?>" />
  494.           <input type="hidden" name="action" value="editlink" />
  495.           <input type="hidden" name="link_id" value="<?php echo (int) $link_id; ?>" />
  496.           <input type="hidden" name="order_by" value="<?php echo wp_specialchars($order_by, 1); ?>" />
  497.           <input type="hidden" name="cat_id" value="<?php echo (int) $cat_id ?>" /></p>
  498.   </form> 
  499. </div>
  500. <?php
  501.     break;
  502.   } // end linkedit
  503.   case __("Show"):
  504.   {
  505.     if (!isset($cat_id) || ($cat_id == '')) {
  506.         if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
  507.         $cat_id = 'All';
  508.     }
  509.     $links_show_cat_id = $cat_id;
  510.     if (!isset($order_by) || ($order_by == '')) {
  511.         if (!isset($links_show_order) || ($links_show_order == ''))
  512.         $order_by = 'order_name';
  513.     }
  514.     $links_show_order = $order_by;
  515.     //break; fall through
  516.   } // end Show
  517.   case "popup":
  518.   {
  519.     $link_url = stripslashes($_GET["linkurl"]);
  520.     $link_name = stripslashes($_GET["name"]);
  521.     //break; fall through
  522.   }
  523.   default:
  524.   {
  525.     if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
  526.         $cat_id = $links_show_cat_id;
  527.  
  528.     if (!isset($cat_id) || ($cat_id == '')) {
  529.         if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
  530.         $cat_id = 'All';
  531.     }
  532.     $links_show_cat_id = $cat_id;
  533.     if (isset($links_show_order) && ($links_show_order != ''))
  534.         $order_by = $links_show_order;
  535.  
  536.     if (!isset($order_by) || ($order_by == ''))
  537.         $order_by = 'order_name';
  538.     $links_show_order = $order_by;
  539.  
  540.     setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
  541.     setcookie('links_show_order_' . COOKIEHASH, $links_show_order, time()+600);
  542.     include_once ("./admin-header.php");
  543.     if ($user_level < 5) {
  544.       die(__("You do not have sufficient permissions to edit the links for this blog."));
  545.     }
  546.  
  547.     switch ($order_by)
  548.     {
  549.         case 'order_id':     $sqlorderby = 'id';          break;
  550.         case 'order_url':    $sqlorderby = 'url';         break;
  551.         case 'order_desc':   $sqlorderby = 'description'; break;
  552.         case 'order_owner':  $sqlorderby = 'owner';       break;
  553.         case 'order_rating': $sqlorderby = 'rating';      break;
  554.         case 'order_name':
  555.         default:             $sqlorderby = 'name';        break;
  556.     }
  557.  
  558.   if ($action != "popup") {
  559. ?>
  560. <script type="text/javascript">
  561. <!--
  562. function checkAll(form)
  563. {
  564.     for (i = 0, n = form.elements.length; i < n; i++) {
  565.         if(form.elements[i].type == "checkbox") {
  566.             if(form.elements[i].checked == true)
  567.                 form.elements[i].checked = false;
  568.             else
  569.                 form.elements[i].checked = true;
  570.         }
  571.     }
  572. }
  573. //-->
  574. </script>
  575.  
  576. <div class="wrap">
  577.     <form name="cats" method="post" action="">
  578.     <table width="75%" cellpadding="3" cellspacing="3">
  579.       <tr>
  580.         <td>
  581.         <?php _e('<strong>Show</strong> links in category:'); ?><br />
  582.         </td>
  583.         <td>
  584.           <?php _e('<strong>Order</strong> by:');?>
  585.         </td>
  586.         <td> </td>
  587.       </tr>
  588.       <tr>
  589.         <td>
  590. <?php
  591.     $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
  592.     echo "        <select name=\"cat_id\">\n";
  593.     echo "          <option value=\"All\"";
  594.     if ($cat_id == 'All')
  595.       echo " selected='selected'";
  596.     echo "> " . __('All') . "</option>\n";
  597.     foreach ($results as $row) {
  598.       echo "          <option value=\"".$row->cat_id."\"";
  599.       if ($row->cat_id == $cat_id)
  600.         echo " selected='selected'";
  601.         echo ">".$row->cat_id.": ".wp_specialchars($row->cat_name);
  602.         if ($row->auto_toggle == 'Y')
  603.             echo ' (auto toggle)';
  604.         echo "</option>\n";
  605.     }
  606.     echo "        </select>\n";
  607. ?>
  608.         </td>
  609.         <td>
  610.           <select name="order_by">
  611.             <option value="order_id"     <?php if ($order_by == 'order_id')     echo " selected='selected'";?>><?php _e('Link ID') ?></option>
  612.             <option value="order_name"   <?php if ($order_by == 'order_name')   echo " selected='selected'";?>><?php _e('Name') ?></option>
  613.             <option value="order_url"    <?php if ($order_by == 'order_url')    echo " selected='selected'";?>><?php _e('URI') ?></option>
  614.             <option value="order_desc"   <?php if ($order_by == 'order_desc')   echo " selected='selected'";?>><?php _e('Description') ?></option>
  615.             <option value="order_owner"  <?php if ($order_by == 'order_owner')  echo " selected='selected'";?>><?php _e('Owner') ?></option>
  616.             <option value="order_rating" <?php if ($order_by == 'order_rating') echo " selected='selected'";?>><?php _e('Rating') ?></option>
  617.           </select>
  618.         </td>
  619.         <td>
  620.           <input type="submit" name="action" value="<?php _e('Show') ?>" />
  621.         </td>
  622.       </tr>
  623.     </table>
  624.     </form>
  625.  
  626. </div>
  627.  
  628. <form name="links" id="links" method="post" action="">
  629. <div class="wrap">
  630.  
  631.     <input type="hidden" name="link_id" value="" />
  632.     <input type="hidden" name="action" value="" />
  633.     <input type="hidden" name="order_by" value="<?php echo wp_specialchars($order_by, 1); ?>" />
  634.     <input type="hidden" name="cat_id" value="<?php echo (int) $cat_id ?>" />
  635.   <table width="100%" cellpadding="3" cellspacing="3">
  636.     <tr>
  637.       <th width="15%"><?php _e('Name') ?></th>
  638.       <th><?php _e('URI') ?></th>
  639.       <th><?php _e('Category') ?></th>
  640.       <th><?php _e('rel') ?></th>
  641.       <th><?php _e('Image') ?></th>
  642.       <th><?php _e('Visible') ?></th>
  643.       <th colspan="2"><?php _e('Action') ?></th>
  644.       <th> </th>
  645.   </tr>
  646. <?php
  647.     $sql = "SELECT link_url, link_name, link_image, link_description, link_visible,
  648.             link_category AS cat_id, cat_name AS category, $wpdb->users.user_login, link_id,
  649.             link_rating, link_rel, $wpdb->users.user_level
  650.             FROM $wpdb->links
  651.             LEFT JOIN $wpdb->linkcategories ON $wpdb->links.link_category = $wpdb->linkcategories.cat_id
  652.             LEFT JOIN $wpdb->users ON $wpdb->users.ID = $wpdb->links.link_owner ";
  653.  
  654.     if (isset($cat_id) && ($cat_id != 'All')) {
  655.       $sql .= " WHERE link_category = $cat_id ";
  656.     }
  657.     $sql .= ' ORDER BY link_' . $sqlorderby;
  658.  
  659.     // echo "$sql";
  660.     $links = $wpdb->get_results($sql);
  661.     if ($links) {
  662.         foreach ($links as $link) {
  663.               $link->link_name = wp_specialchars($link->link_name);
  664.               $link->link_category = wp_specialchars($link->link_category);
  665.               $link->link_description = wp_specialchars($link->link_description);
  666.             $link->link_url = wp_specialchars($link->link_url);
  667.             $short_url = str_replace('http://', '', $link->link_url);
  668.             $short_url = str_replace('www.', '', $short_url);
  669.             if ('/' == substr($short_url, -1))
  670.                 $short_url = substr($short_url, 0, -1);
  671.             if (strlen($short_url) > 35)
  672.                 $short_url =  substr($short_url, 0, 32).'...';
  673.  
  674.             $image = ($link->link_image != null) ? __('Yes') : __('No');
  675.             $visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
  676.             ++$i;
  677.             $style = ($i % 2) ? ' class="alternate"' : '';
  678. ?>
  679.     <tr valign="middle" <?php echo $style; ?>>
  680.         <td><strong><?php echo $link->link_name; ?></strong><br />
  681. <?php            
  682.         echo sprintf(__('Description: %s'), $link->link_description) . "</td>";
  683.         echo "<td><a href=\"$link->link_url\" title=\"" . sprintf(__('Visit %s'), $link->link_name) . "\">$short_url</a></td>";
  684.         echo <<<LINKS
  685.         <td>$link->category</td>
  686.         <td>$link->link_rel</td>
  687.         <td align='center'>$image</td>
  688.         <td align='center'>$visible</td>
  689. LINKS;
  690.             $show_buttons = 1; // default
  691.  
  692.             if ($link->user_level > $user_level) {
  693.               $show_buttons = 0;
  694.             }
  695.  
  696.             if ($show_buttons) {
  697.         echo '<td><a href="link-manager.php?link_id=' . $link->link_id . '&action=linkedit" class="edit">' . __('Edit') . '</a></td>';
  698.         echo '<td><a href="link-manager.php?link_id=' . $link->link_id . '&action=Delete"' .  " onclick=\"return confirm('" . __("You are about to delete this link.\\n  \'Cancel\' to stop, \'OK\' to delete.") .  "');" . '" class="delete">' . __('Delete') . '</a></td>';
  699.         echo '<td><input type="checkbox" name="linkcheck[]" value="' . $link->link_id . '" /></td>';
  700.             } else {
  701.               echo "<td> </td><td> </td><td> </td>\n";
  702.             }
  703.         echo "\n\t</tr>";
  704.         }
  705.     }
  706. ?>
  707. </table>
  708.  
  709. </div>
  710.  
  711. <div class="wrap">
  712.   <table width="100%" cellpadding="3" cellspacing="3">
  713.     <tr><th colspan="4"><?php _e('Manage Multiple Links:') ?></th></tr>
  714.     <tr><td colspan="4"><?php _e('Use the checkboxes on the right to select multiple links and choose an action below:') ?></td></tr>
  715.     <tr>
  716.         <td>
  717.           <?php _e('Assign ownership to:'); ?>
  718. <?php
  719.     $results = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users WHERE user_level > 0 ORDER BY ID");
  720.     echo "          <select name=\"newowner\" size=\"1\">\n";
  721.     foreach ($results as $row) {
  722.       echo "            <option value=\"".$row->ID."\"";
  723.       echo ">".$row->user_login;
  724.       echo "</option>\n";
  725.     }
  726.     echo "          </select>\n";
  727. ?>
  728.         <input name="assign" type="submit" id="assign" value="<?php _e('Go') ?>" />
  729.         </td>
  730.         <td>
  731.           <input name="visibility" type="submit" id="visibility" value="<?php _e('Toggle Visibility') ?>" />
  732.         </td>
  733.         <td>
  734.           <?php _e('Move to category:'); category_dropdown('category'); ?> <input name="move" type="submit" id="move" value="<?php _e('Go') ?>" />
  735.         </td>
  736.         <td align="right">
  737.           <a href="#" onclick="checkAll(document.getElementById('links')); return false; "><?php _e('Toggle Checkboxes') ?></a>
  738.         </td>
  739.     </tr>
  740. </table>
  741.  
  742. <?php
  743.   } // end if !popup
  744. ?>
  745. </div>
  746. </form>
  747.  
  748.  
  749. <?php
  750.     break;
  751.   } // end default
  752. } // end case
  753. ?>
  754.  
  755. <?php include('admin-footer.php'); ?>
  756.